import 'package:cached_network_image/cached_network_image.dart';
import 'package:find_friend/pages/login&register/model/shared_user_info.dart';
import 'package:find_friend/pages/mine/mine_photos_wall.dart';
import 'package:find_friend/pages/xspace/model/school_model.dart';
import 'package:flutter/material.dart';
import 'package:find_friend/const/const.dart';
import 'dart:math';

class XallImageWidget extends StatelessWidget {

  final List<Photo> list;
  String heroPerfix;

  XallImageWidget({Key key, this.list}) : super(key: key){
    heroPerfix = Random().nextDouble().toString();
  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    double width = size.width * 0.75;
    double height = 150;
    if(list.length != 1) {
      height = 100;
      width = size.width * 0.7 / 2.0;
    }
    return Wrap(
      spacing: 2.5,
      runSpacing: 2.5,
      children: list.map((e) => 
        GestureDetector(
          onTap: (){
            List<FileModel> temp = list.map((e) => FileModel(url: e.url, id: 0, audiourl: e.ownerUrl, duration: e.playtime)).toList();
            Navigator.push(context, PageRouteBuilder(
              pageBuilder: (BuildContext context, Animation animation,
                  Animation secondaryAnimation) {
                return new FadeTransition(
                  opacity: animation,
                  child: MinePhotoWallPage(list: temp,heroTag: heroPerfix + e.url + list.indexOf(e).toString()),
                );
              })
            ); 
            
          },
          child: Stack(
            children: [
              PhysicalModel(
                color: Colors.white,
                borderRadius: BorderRadius.circular(5),
                clipBehavior: Clip.antiAlias,
                child: Hero(
                  tag: heroPerfix + e.url + list.indexOf(e).toString(), // 与个人中心区分
                  // child: Image.network(e.url, width: width, height: height,fit: BoxFit.cover,)
                  child: CachedNetworkImage(
                    imageUrl: e.url,
                    width: width, 
                    height: height,
                    fit: BoxFit.cover,
                  ),
                )
              ),
              Positioned(
                bottom: 10,
                left: 10,
                child: Offstage(
                  offstage: e.ownerUrl == null,
                  child: Image.asset("assets/shengyin3.png")
                ),
              )
            ],
          ),
        )
      ).toList(),
    );
  }
}